package transfers

import (
	"crypto/md5"
	"crypto/tls"
	"fmt"
	"github.com/tobyzxj/uuid"
	"strings"
)

var _tlsConfig *tls.Config

//采用单例模式初始化ca
func getTLSConfig(certF, keyF string) (*tls.Config, error) {
	if _tlsConfig != nil {
		return _tlsConfig, nil
	}

	cert, err := tls.LoadX509KeyPair(certF, keyF)
	if err != nil {
		return nil, err
	}

	_tlsConfig = &tls.Config{
		Certificates: []tls.Certificate{cert},
	}
	return _tlsConfig, nil
}

func GetRandomString() string {
	return strings.Replace(uuid.New(), "-", "", -1)
}

func Md5(data []byte) string {
	has := md5.Sum(data)
	md5str1 := fmt.Sprintf("%X", has) //将[]byte转成16进制
	return md5str1
}
